import numpy as np
import matplotlib.pyplot as plt

w = np.linspace(-1, 1, 30)
e = w ** 2

current_w = max(w)
# 学习率 分别取 0.2、0.02、0.9 学习图线会呈现不一样的状态
lr = 0.9
num_epochs = 10
predict_w = []
for i in range(num_epochs):
    predict_w.append(current_w)
    slope = 2 * current_w
    # SGD 小固定值 * 斜率
    current_w -= lr * slope
    predict_w.append(current_w)

predict_w = np.array(predict_w)
plt.plot(w, e, 'r-')
plt.plot(predict_w, predict_w ** 2, 'bo-')
plt.show()
